package Service.Teacher.Imp;

import Dao.DaoFactory;
import Dao.Process.MediumDao;
import Dao.Process.ReportDao;
import Dao.Process.StageCheckDao;
import Dao.Process.TaskDao;
import Dao.Role.StuInfoDao;
import Dao.TitleAndPaper.PaperDao;
import Service.Teacher.StuSumService;
import Util.DBUtil;

import java.sql.Connection;

public class StuSumServiceImp implements StuSumService {
    private Connection conn;
    private StuInfoDao stuInfoDao;
    private PaperDao paperDao;
    private TaskDao taskDao;
    private ReportDao reportDao;
    private MediumDao mediumDao;
    private StageCheckDao stageCheckDao;


    public StuSumServiceImp() {
        conn = DBUtil.getConnByDruid();
        stuInfoDao = DaoFactory.getInstance("stuInfoDao");
        paperDao = DaoFactory.getInstance("paperDao");
        taskDao = DaoFactory.getInstance("taskDao");
        reportDao = DaoFactory.getInstance("reportDao");
        mediumDao = DaoFactory.getInstance("mediumDao");
        stageCheckDao = DaoFactory.getInstance("stageCheckDao");
    }


    /**
     * 得到学生总数 和已选题的人数
     *
     * @param TNO 老师的编号
     * @return 两个人数的组合 @ 连接
     */
    @Override
    public String getChooseSumByTNO(String TNO) {
        int sum1 = stuInfoDao.getSumByTNO(TNO, conn);
        int sum2 = paperDao.getSumByTNO(TNO, conn);
        String sum = sum1 + "@" + sum2;
        DBUtil.closeConn(conn);
        return sum;
    }

    /**
     * 得到各个阶段的完成人数
     *
     * @param TNO 老师的编号
     * @return 人数
     */
    @Override
    public String getSumByTNO(String TNO, Integer type) {
        int sum1 = taskDao.getSumByTNO(TNO, type, conn); // 任务书的完成人数
        int sum2 = reportDao.getSumByTNO(TNO, type, conn); //开题报告
        int sum3 = mediumDao.getSumByTNO(TNO, type, conn); //中期检查
        int sum4 = stageCheckDao.getSumByTNO(TNO, type, "初稿", conn); // 初稿
        int sum5 = stageCheckDao.getSumByTNO(TNO, type, "定稿", conn); // 定稿
        int sum6 = stageCheckDao.getSumByTNO(TNO, type, "终稿", conn); // 终稿
        String sum = sum1 + "@" + sum2 + "@" + sum3 + "@" + sum4 + "@" + sum5 + "@" + sum6;
        DBUtil.closeConn(conn);
        return sum;
    }
}
